package com.kyle.api;

import com.kyle.api.intercept.SMSInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author：kyle_fu
 * @description: TODO
 * @Date：2024/2/14 13:09
 * @version: 1.0
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 在springboot容器中放入拦截器
     * @return
     */
    @Bean
    public SMSInterceptor smsInterceptor(){
        return new SMSInterceptor();
    }

    /**
     * 注册拦截器,拦截指定的路由,否则不生效
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(smsInterceptor())
                    .addPathPatterns("/passport/getSMSCode");
    }
}
